﻿using DataAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace KhoaLuan.MainSys.Controls
{
    public partial class ctViewArticle : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {

                    var id = Request.QueryString["ArticleID"];
                    if (id != null)
                    {

                        var proxy = new tbPosts_Proxy();
                        var article = proxy.GetById_tbPosts_Proxy(Convert.ToInt32(id)).ToObject<tbPosts>();
                        if (article.Active == 1)
                        {
                            lbTieuDe.Text = article.Title;
                            lbNoiDung.Text = HttpUtility.HtmlDecode(article.Content);
                            if (article.ImagePath != null)
                            {
                                imgHinhMinhHoa.ImageUrl = article.ImagePath;
                                imgHinhMinhHoa.ImageAlign = ImageAlign.Left;
                            }
                            else
                            {
                                imgHinhMinhHoa.Visible = false;
                            }
                            var proxyorg = new tbOrg_Proxy();
                            var org = proxyorg.GetById_tbOrg_Proxy(article.OrgID).ToObject<tbOrg>();
                            if (org != null)
                                lbDonVi.Text = "Đơn vị: " + org.NameOrg;
                            var date = article.CreatedDate;
                            if (article.UpdatedDate != null)
                                date = article.UpdatedDate.Value;
                            lbNgay.Text = "Ngày " + date.Day + " Tháng " + date.Month + " Năm " + date.Year;
                        }
                    }
                }
                catch (Exception)
                {

                }
            }
        }
    }
}